<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=1, initial-scale=1.0">
    <title>Document</title>
    <script src="../lib/vue.js"></script>
</head>
<body>
    <div id="app">
        <h2>Vue 实现简单的留言板 </h2>
        <div>
            <p v-for="(item,index) in words" >{{item}} - {{index}}</p>
        </div>
        <div>
            <h2>展示留言</h2>
            <div v-for="(l,i) in list" >
                 <span>{{l.title}}</span> 
                 <button v-on:click="list.splice(i,1)">删除</button>
                 <button v-on:click="setItemOne(l,i)">修改</button>
            </div>
        </div>
        <div>
            <h2>添加留言</h2>
            <p>
                <input type="text" v-model="text">
                <button v-on:click="addData">提交</button>
            </p>
        </div>
    </div>

    <script>
        const vm = new Vue({
            el:"#app",
            data:{
                words:["花好月圆","圆圆满满","满满当当","当机立断","断章取义"],
                list:[
                    {title:"情人节快乐"},
                    {title:"元宵节快乐"},
                    {title:"女人节快乐"},
                    {title:"妇女节快乐"},
                ],
                text:"666快乐"
            },
            methods:{
                addData(){
                    this.list.push({
                        title:this.text
                    })
                    this.text= ""
                },
                setItemOne(item,index){
                    let value = window.prompt(index,item.title)
                    console.log(value)
                    if(value){
                        // this.list.splice(index,1,{title:value})
                        this.list[index].title = value 
                    }
                }
            }
        })
    </script>
</body>
</html>